﻿namespace JNPF.Utils
{
    /// <summary>
    /// 租户上下文提供者
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// </summary>
    public static class TenantProvider
    {
        public static TenantInfo GetTenant
        {
            get
            {
                var tenantDbConnectionString = WebHelper.HttpGetItems("TenantDbConnectionString");
                if (tenantDbConnectionString != null)
                {
                    return new TenantInfo
                    {
                        TenantId = WebHelper.HttpGetItems("TenantId").ToString(),
                        TenantDbType = WebHelper.HttpGetItems("TenantDbType").ToString(),
                        TenantDbConnectionString = tenantDbConnectionString.ToString()
                    };
                }
                else
                {
                    var userInfo = UserProvider.Instance.Get();
                    if (userInfo != null)
                    {
                        return new TenantInfo
                        {
                            TenantId = userInfo.TenantId,
                            TenantDbType = userInfo.TenantDbType,
                            TenantDbConnectionString = userInfo.TenantDbConnectionString
                        };
                    }
                    else
                    {
                        return new TenantInfo { TenantId = "", TenantDbType = "", TenantDbConnectionString = "" };
                    }
                }
            }
        }
    }
}
